/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package introse;

/**
 *
 * @author Alfred
 */
public class reactivateProducts extends javax.swing.JDialog {

    private uneditableTableModel productTableModel;
    private productManager productMngr;
    
    public reactivateProducts(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        loadDisabledProductTable();
    }
    
     public void loadDisabledProductTable() {
        //Reset Product List And Table
        productMngr = new productManager();
        productTableModel = new uneditableTableModel(new String[]{"Product Number", "Stock Add", "Stock Less", "isActive", "Product Name", "Product Type", "Price", "Stock"});
        productTable.setModel(productTableModel);

        //Hide first 4 columns (Product Number, Stock Add, Stock Less, isActive)
        productTable.removeColumn(productTable.getColumnModel().getColumn(0));
        productTable.removeColumn(productTable.getColumnModel().getColumn(0));
        productTable.removeColumn(productTable.getColumnModel().getColumn(0));
        productTable.removeColumn(productTable.getColumnModel().getColumn(0));

        //Load products from clientManager to table
     /*
         * regenerated by the Form Editor.
         */
        for (product prod : productMngr.getProducts(false)) {
            productTableModel.addRow(new String[]{Integer.toString(prod.getProductNumber()), Integer.toString(prod.getStockAdd()), Integer.toString(prod.getStockMinus()), Boolean.toString(prod.getIsActive()), prod.getProductName(), prod.getIsGasul() ? "Gasul" : "Miscellaneous", Float.toString(prod.getPrice()), Integer.toString(prod.getStock() + prod.getStockAdd() - prod.getStockMinus())});
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        productTable = new javax.swing.JTable();
        reactivate = new javax.swing.JButton();
        close = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        productTable.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        productTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(productTable);

        reactivate.setText("Reactivate Product");
        reactivate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reactivateActionPerformed(evt);
            }
        });

        close.setText("Close");
        close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(196, 196, 196)
                        .addComponent(reactivate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(close)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(reactivate)
                    .addComponent(close))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeActionPerformed
        this.dispose();
    }//GEN-LAST:event_closeActionPerformed

    private void reactivateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reactivateActionPerformed
        try {
            int productNumber = Integer.parseInt(productTableModel.getValueAt(productTable.getSelectedRow(), 0).toString());
            productMngr.getProduct(productNumber).setIsActive(true);
            positiveMessage posMsg = new positiveMessage(null, true);
            posMsg.setMessage("Product has been reactivated");
            posMsg.setVisible(true);
        } catch (Exception ex) {
            errorDialogue errorMessage = new errorDialogue(null, true);
            errorMessage.setMessage("No product selected");
            errorMessage.setVisible(true);
        }
        loadDisabledProductTable();
    }//GEN-LAST:event_reactivateActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(reactivateProducts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(reactivateProducts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(reactivateProducts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(reactivateProducts.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                reactivateProducts dialog = new reactivateProducts(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton close;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable productTable;
    private javax.swing.JButton reactivate;
    // End of variables declaration//GEN-END:variables
}
